from typing import List

from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> List[str]:
    return [
        """ALTER TABLE `cart_items` DROP FOREIGN KEY `fk_cart_ite_coffee_p_eaf99bd2`""",
        """ALTER TABLE `cart_items` ADD `product_type` VARCHAR(11) NOT NULL  COMMENT '商品类型' DEFAULT 'coffee'""",
        """ALTER TABLE `cart_items` MODIFY COLUMN `product_id` INT NOT NULL  COMMENT '商品ID（咖啡或周边）'""",
        """ALTER TABLE `cart_items` MODIFY COLUMN `product_id` INT NOT NULL  COMMENT '商品ID（咖啡或周边）'"""
    ]


async def downgrade(db: BaseDBAsyncClient) -> List[str]:
    return [
        """ALTER TABLE `cart_items` DROP COLUMN `product_type`""",
        """ALTER TABLE `cart_items` MODIFY COLUMN `product_id` INT NOT NULL""",
        """ALTER TABLE `cart_items` MODIFY COLUMN `product_id` INT NOT NULL""",
        """ALTER TABLE `cart_items` ADD CONSTRAINT `fk_cart_ite_coffee_p_eaf99bd2` FOREIGN KEY (`product_id`) REFERENCES `coffee_products` (`id`) ON DELETE CASCADE"""
    ]
